import * as types from './organBaoMutationTypes';
// import assignDeep from 'assign-deep';

/**
 * mutations
 * @type {{}}
 */
const mutations = {

  [types.ORGAN_BAO_QUERY_BEGIN] (state) {
    state.organBao = []
  },

  [types.ORGAN_BAO_QUERY_SUC] (state, {organBao}) {
    state.organBao = organBao || []
  },

  [types.ONLINE_ORGAN_BAO_QUERY_BEGIN] (state) {
    state.onlineOrganBao = []
  },

  [types.ONLINE_ORGAN_BAO_QUERY_SUC] (state, {onlineOrganBao}) {
    state.onlineOrganBao = onlineOrganBao || []
  },

  [types.ORGAN_BAO_QUERY_COUNT_BEGIN] (state) {
    state.totalCount = 0
  },

  [types.ORGAN_BAO_QUERY_COUNT_SUC] (state, {totalCount}) {
    state.totalCount = totalCount
  },
  [types.SYS_RECOMMENDS_UPLOAD_UPDATE_SUC](state, {fundCode}) {

    if (fundCode === '-1') {
      for (var i = 0; i < state.organBao.length; i++) {
        state.organBao[i].isRecommend = false
      }
    } else {
      for (var j = 0; j < state.organBao.length; j++) {
        if (state.organBao[j].fundCode === fundCode) {
          state.organBao[j].isRecommend = true
        } else {
          state.organBao[j].isRecommend = false
        }
      }
    }
  },
  [types.SYS_FILE_UPLOAD_UPDATE_SUC] (state, {formData}) {
  },
  [types.ORGAN_BAO_UPLOAD_ADD_SUC] (state, {formData}) {
    let organBaos = state.organBao || [];
    organBaos.push(formData);
  },
  [types.ORGAN_BAO_ONLINE_SUC](state, {fundCode}) {
    for (let i = 0; i < state.organBao.length; i++) {
      let item = state.organBao[i];
      if (item.fundCode === fundCode) {
        if (item.isValid === true) {
          item.isValid = false
        } else {
          item.isValid = true
        }
        break;
      }
    }
  }
};

export default mutations;
